﻿using Maticsoft.DBUtility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace BBPA.DAL
{
   public class Stat
    {
       public static void Increase(string TableName_,string columnName_,int RowID_, object addNum_ )
       {
           string[] dataTypeA = { "day", "week", "month", "year" };
           for (int i = 0; i < dataTypeA.Length; i++)
           {
               DataSet ds = DbHelperSQL.Query("select * from " + TableName_ + " where datediff(" + dataTypeA [i]+ ",[DateFrom],getdate())=0 and DateType=" + i + " and RowID=" + RowID_);
               if (ds == null || (ds != null && ds.Tables.Count == 0) || (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count == 0))
                   DbHelperSQL.ExecuteSql("insert into " + TableName_ + " (" + columnName_ + ",DateType,RowID,DateFrom) values (" + addNum_ + "," + i + "," + RowID_ + ", DATEADD(" + dataTypeA[i] + ", DATEDIFF(" + dataTypeA[i] + ",0,getdate()), 0) )");
               else DbHelperSQL.ExecuteSql("update " + TableName_ + " set " + columnName_ + "=" + columnName_ + "+" + addNum_ + " where id=" + ds.Tables[0].Rows[0]["id"]);
           }
           
       }
    }
}
